﻿CREATE PROCEDURE [dbo].[UpdateActivityRoleAccess]
	@ActivityRoleAccessId uniqueidentifier,
    @Permissions int,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE ActivityRoleAccess

	SET 

	 [Permissions] = @Permissions,
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE ActivityRoleAccessId = @ActivityRoleAccessId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM ActivityRoleAccess 

	WHERE ActivityRoleAccessId = @ActivityRoleAccessId

RETURN 0